package main.Q501_600;

import java.util.Arrays;

public class Q571_580 {
    public static void main(String[] args) {
        System.out.println("Question571：");
        System.out.println("Question572：另一棵数的子树");
        System.out.println("Question573：");
        System.out.println("Question574：");
        System.out.println("Question575：分糖果");
        System.out.println("Question576：");
        System.out.println("Question577：");
        System.out.println("Question578：");
        System.out.println("Question579：");
        System.out.println("Question580：");
    }
}

class Question572{
    public boolean isSubtree(TreeNode s, TreeNode t) {
        return dfs(s, t);
    }

    public boolean dfs(TreeNode s, TreeNode t) {
        if (s == null) return false;
        return check(s, t) || dfs(s.left, t) || dfs(s.right, t);
    }

    public boolean check(TreeNode s, TreeNode t) {
        if (s == null && t == null) return true;
        if (s == null || t == null || s.val != t.val) return false;
        return check(s.left, t.left) && check(s.right, t.right);
    }
}

class Question575{
    public static int distributeCandies(int[] candyType) {
        int count=candyType.length/2,typeCount=1;
        Arrays.sort(candyType);
        for (int i=1;i<candyType.length;i++) if (candyType[i-1]!=candyType[i]) typeCount++;
        return Math.min(typeCount,count);
    }
}